package com.example.springbootrabbitmq.component;

import com.example.springbootrabbitmq.service.OmsPortalOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 取消订单消息的处理者<br/>
 * 用于从取消订单的消息队列（mall.order.cancel）里接收消息。
 */

@Component
@RabbitListener(queues = {"mall.order.cancel"})
public class CancelOrderReceiver {
    private static final Logger LOGGER = LoggerFactory.getLogger(CancelOrderReceiver.class);

    @Resource
    private OmsPortalOrderService portalOrderService;

    /*
    @RabbitListener 可以标注在类上面，需配合 @RabbitHandler 注解一起使用
    @RabbitListener 标注在类上面表示当队列收到消息的时候，就交给 @RabbitHandler 的方法处理，
    具体使用哪个方法处理，根据 MessageConverter 转换后的参数类型
     */
    @RabbitHandler
    public void handle(Long orderId) {
        LOGGER.info("receive delay message orderId:{}", orderId);
        portalOrderService.cancelOrder(orderId);
    }
}
